#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int N;
int b[10][10];
int f[10][10];
int ans = 0;
int pathtot = 0;

// tot 4down 4right
//

void dfs(int x, int y, int tot) {
    int mem = b[x][y];
    b[x][y] = 0;
    if (x != N - 1 || y != N - 1) {
        if (x != N - 1) dfs(x + 1, y, tot + b[x + 1][y]);
        if (y != N - 1) dfs(x, y + 1, tot + b[x][y + 1]);
    } else {
        pathtot++;
        memset(f, 0, sizeof(f));
        f[0][0] = b[0][0];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (i == 0 && j > 0)
                    f[i][j] = f[i][j - 1] + b[i][j];
                else if (j == 0 && i > 0)
                    f[i][j] = f[i - 1][j] + b[i][j];
                else
                    f[i][j] = b[i][j] + max(f[i - 1][j], f[i][j - 1]);
            }
        }
        ans = max(ans, tot + f[N - 1][N - 1]);
    }
    b[x][y] = mem;
}

int main() {
    cin >> N;
    memset(b, 0, sizeof(b));
    memset(f, 0, sizeof(f));
    while (true) {
        int x, y, v;
        cin >> x >> y >> v;
        if (!x && !y && !v)
            break;
        else
            b[x - 1][y - 1] = v;
    }

    dfs(0, 0, b[0][0]);

    cout << ans << endl
         << pathtot;
}